package online.yangcloud.web.service.meta.impl;

import com.mybatisflex.core.query.QueryWrapper;
import online.yangcloud.common.enumration.YesOrNoEnum;
import online.yangcloud.common.tools.ExceptionTools;
import online.yangcloud.core.mapper.GlobalMapper;
import online.yangcloud.core.model.entity.AudioEntity;
import online.yangcloud.web.service.meta.AudioMetaService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhuboyang
 * @since 2023年09月22 20:10:59
 */
@Service
public class AudioMetadataServiceImpl implements AudioMetaService {

    @Resource
    private GlobalMapper globalMapper;

    @Override
    public void addAudioRecord(AudioEntity metadata) {
        ExceptionTools.updateError(globalMapper.acquireAudio().insertWithPk(metadata));
    }

    @Override
    public AudioEntity queryAudioByFileId(String id) {
        return globalMapper.acquireAudio().selectOneByQuery(QueryWrapper.create()
                .where(AudioEntity::getFileId).eq(id)
                .and(AudioEntity::getIsDelete).eq(YesOrNoEnum.NO.code()));
    }

    @Override
    public List<AudioEntity> queryAudiosByFileIds(List<String> fileIds) {
        return globalMapper.acquireAudio().selectListByQuery(QueryWrapper.create()
                .where(AudioEntity::getFileId).in(fileIds)
                .and(AudioEntity::getIsDelete).eq(YesOrNoEnum.NO.code()));
    }

}
